package cn.wolfcode.plus.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.wolfcode.plus.domain.RedPacketInfo;
import cn.wolfcode.plus.service.RedPacketInfoService;
import cn.wolfcode.plus.mapper.RedPacketInfoMapper;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 *
 */
@Service
public class RedPacketInfoServiceImpl extends ServiceImpl<RedPacketInfoMapper, RedPacketInfo>
    implements RedPacketInfoService{

    @Override
    public int snatch(RedPacketInfo redPacketInfo) {

        // 设置最大的红包金额
        Integer amount = redPacketInfo.getRemainingAmount();
        Integer count = redPacketInfo.getRemainingPacket();
        System.out.println("里面count = " + count);
        System.out.println("amount = " + amount);
        int maxMoney = amount / count * 2;
        System.out.println("maxMoney = " + maxMoney);
        // 随机取金额, 如果只剩下一个,为剩下的全部金额
        Random random = new Random();
        return count == 1 ? amount : random.nextInt(maxMoney);
    }
}




